﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace NQueries
{
    /// <summary>
    /// An System.Collections.ObjectModel.ObservableCollection that raises individual item removal notifications on clear and prevents adding duplicates.
    /// </summary>
    [Serializable]
    public class FixupCollection<T> : ObservableCollection<T>
    {
        /// <summary>
        /// Deletes all items.
        /// </summary>
        protected override void ClearItems() { new List<T>(this).ForEach(t => Remove(t)); }

        /// <summary>
        /// Inserts a new item.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="item"></param>
        protected override void InsertItem(int index, T item)
        {
            if (!Contains(item))
                base.InsertItem(index, item);
        }
    }
}